{include header}
<div class="wrapper">
    {include header_menu}

    {include left_menu}
    <div class="main-container">
        <div class="padding-md">
            <h2 class="header-text no-margin">
                用户组 管理
            </h2>
            <div class="gallery-filter m-top-md m-bottom-md">
                <ul class="clearfix">
                    <li class="active"><a href="javascript:void(0)" data-toggle="modal" data-target="#normalModal"><i class="fa fa-plus"></i> 添加用户组</a></li>
                </ul>
            </div>
            
            <script>
          
            function del_group(id,obj){
                swal({
                    title: "确认删除？",
                    text: '切勿随意删除用户组，删除前先确认是否有用户正在使用该用户组。删除后无法恢复用户组！',
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "删除",
                    cancelButtonText:'取消',

                }).then(
                    function(){
                        $(obj).attr("disabled", true);

                        $.post('{php HYBBS_URL('admin','usergroup')}',{id:id,gn:'del'},function(e) {
                            $(obj).removeAttr("disabled");
                            if (e.error) {
                                swal(e.info,'页面自动刷新中...','success');
                                setTimeout(function(){
                                    location.reload();    
                                },500);
                                
                            }

                        }, 'json');
                    },
                    function(e){
                        console.log(e);
                    }
                );

               

            }
            function edit_forum(obj){
                var _this = $(obj);
                $('#edit-iid').val(_this.data('gid'));
                $('#edit-id').val(_this.data('gid'));
                // if(parseInt(_this.data('gid')) <= 3){
                //     $('#edit-id').attr('disabled','disabled');
                // }else{
                //     $('#edit-id').removeAttr('disabled');
                // }

                // if(parseInt(_this.data('gid')) == 1 || parseInt(_this.data('gid')) == 3){
                //     $('#edit-credits').attr('disabled','disabled');
                //     $('#edit-credits-max').attr('disabled','disabled');
                // }else{
                //     $('#edit-credits').removeAttr('disabled');
                //     $('#edit-credits-max').removeAttr('disabled');
                // }


                $('#edit-name').val(_this.data('name'));
                $('#edit-credits').val(_this.data('credits'));
                $('#edit-credits-max').val(_this.data('credits-max'));
                $('#edit-space-size').val(_this.data('space-size'));
                $('#edit-chat-size').val(_this.data('chat-size'));
                $('#edit-font-color').val(_this.data('font-color'));

                $('#edit-font-css').val($('#pre-'+_this.data('gid')).html());

                $('#normalModal1').modal('show')
            }
            // function edit_user(obj,id,type,b){



            //     $.post('{php HYBBS_URL('admin','usergroup')}',{gn:3,id:id,b:b,type:type},function(e){
            //         if(e.error){
            //             var bb = b ? 0 : 1;
            //             if(b){
            //                 $(obj).attr('onclick',"edit_user(this,"+id+",'"+type+"',"+ bb +")");
            //                 $(obj).text("禁止");
            //                 $(obj).removeClass('btn-success').addClass('btn-danger');
            //             }else{
            //                 $(obj).attr('onclick',"edit_user(this,"+id+",'"+type+"',"+ bb +")");
            //                 $(obj).text("允许");
            //                 $(obj).removeClass('btn-danger').addClass('btn-success');
            //             }

            //         }
            //     },'json')
            // }

            window.onload = function(){
                $('.mui-switch-box input').click(function(){
                    loading('修改中');
                    var _this = $(this);
                    var gid   = _this.data('gid');
                    var type  = _this.data('type');
                    $.ajax({
                        url:'{php HYBBS_URL('admin','usergroup')}',
                        type:'post',
                        data:{
                            gn:'edit_permission',
                            id:gid,
                            type:type,
                            b:_this.prop('checked') ? 0:1
                        },
                        dataType:'json',
                        success:function(e){
                            wait_close();
                            if(!e.error){
                                swal('无法切换',e.info,'error');
                            }
                            else{
                                if(e.state){
                                    _this.removeAttr("checked"); 
                                    console.log('禁止使用');
                                    
                                }else{
                                    _this.attr("checked","true");
                                    console.log('开放');
                                }
                                
                            }

                        },
                        error:function(e){
                            wait_close();
                        }

                    })
                });
            }


            </script>
            <div class="alert alert-success alert-custom alert-dismissible" role="alert">
                <i class="fa fa-warning m-right-xs"></i> <strong>积分段说明:</strong> 用户的积分处于用户组什么积分段则使用什么用户>
            </div>
            <div class="alert alert-danger alert-custom alert-dismissible" role="alert">
                <i class="fa fa-warning m-right-xs"></i> <strong>特殊说明:</strong> &lt;管理员&gt;&lt;新用户&gt;&lt;游客&gt; 这3个是HYBBS必须使用的用户组. 请勿删除!
            </div>
            <div class="table-responsive">
                <table class="table table-striped table-bordered m-top-md" id="dataTable" >
                    <thead>
                        <tr class="bg-dark-blue">
                            <th></th>
                            {foreach $data as $v}
                            <th>{$v.name} 
                                <button data-gid="{$v.gid}" data-name="{$v.name}" data-credits="{$v.credits}" data-credits-max="{$v.credits_max}" data-space-size="{$v.space_size}" data-chat-size="{$v.chat_size}" data-font-color="{$v.font_color}" type="button" onclick="edit_forum(this)" class="btn btn-success btn-xs"><i class="fa fa-edit"></i></button>
                                {if !in_array($v['gid'],array(1,2,3))}
                                <button type="button" onclick="del_group({$v.gid},this)" class="pull- btn btn-danger btn-xs"><i class="fa fa-remove "></i> </button>
                                {/if}

                                 
                            </th>
                            {/foreach}
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>GID</td>
                            {foreach $data as $v}
                            <td>{$v.gid}</td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>用户组名称</td>
                            {foreach $data as $v}
                            <td><font color="{$v.font_color}" style="{$v.font_css}">{$v.name}</font></td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>积分段</td>
                            {foreach $data as $v}
                            <td>{$v.credits} ~ {$v.credits_max}</td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>字体颜色</td>
                            {foreach $data as $v}
                            <td>{$v.font_color} <i style="background: {$v.font_color};float: left;width: 20px;height: 20px;display: inline-block;border-radius: 4px;margin-right:5px"></i></td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>额外CSS</td>
                            {foreach $data as $v}
                            <td><pre id="pre-{$v.gid}" style="max-height:200px">{$v.font_css}</pre></td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>上传空间</td>
                            {foreach $data as $v}
                            <td>{if $v['gid'] != 3}{$v.space_size}（kb）{/if}</td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>聊天记录空间</td>
                            {foreach $data as $v}
                            <td>{if $v['gid'] != 3}{$v.chat_size}（b）{/if}</td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>目前用户量</td>
                            {foreach $data as $v}
                            <td>{if $v['gid'] != 3}{:M('User')->count(['gid'=>$v['gid']])}{/if}</td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>权限管理</td>
                            {foreach $data as $v}
                            <td>-</td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>允许发帖</td>
                            {foreach $data as $v}
                            <td>
                                {if $v['gid'] != 3}
                                <label class="mui-switch-box">
                                    <input data-type="thread" data-gid="{$v.gid}" class='tgl tgl-ios' id='cb1{$v.gid}' type='checkbox' {if $v['json']['thread']}checked{/if}>
                                    <label class='tgl-btn' for='cb1{$v.gid}'></label>
                                </label>
                                {/if}
                            </td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>允许评论</td>
                            {foreach $data as $v}
                            <td>
                                {if $v['gid'] != 3}
                                <label class="mui-switch-box">
                                    
                                    <input data-type="post" data-gid="{$v.gid}" class='tgl tgl-ios' id='cb2{$v.gid}' type='checkbox' {if $v['json']['post']}checked{/if}>
                                    <label class='tgl-btn' for='cb2{$v.gid}'></label>
                                </label>
                                {/if}
                            </td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>允许按特@</td>
                            {foreach $data as $v}
                            <td>
                                {if $v['gid'] != 3}
                                <label class="mui-switch-box">
                                    
                                    <input data-type="mess" data-gid="{$v.gid}" class='tgl tgl-ios' id='cb3{$v.gid}' type='checkbox' {if $v['json']['mess']}checked{/if}>
                                    <label class='tgl-btn' for='cb3{$v.gid}'></label>
                                </label>
                                {/if}
                            </td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>上传图片</td>
                            {foreach $data as $v}
                            <td>
                                {if $v['gid'] != 3}
                                <label class="mui-switch-box">
                                    
                                    <input data-type="upload" data-gid="{$v.gid}" class='tgl tgl-ios' id='cb4{$v.gid}' type='checkbox' {if $v['json']['upload']}checked{/if}>
                                    <label class='tgl-btn' for='cb4{$v.gid}'></label>
                                </label>
                                {/if}
                            </td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>删除帖子</td>
                            {foreach $data as $v}
                            <td>
                                {if $v['gid'] != 3}
                                <label class="mui-switch-box">
                                    
                                    <input data-type="del" data-gid="{$v.gid}" class='tgl tgl-ios' id='cb5{$v.gid}' type='checkbox' {if $v['json']['del']}checked{/if}>
                                    <label class='tgl-btn' for='cb5{$v.gid}'></label>
                                </label>
                                {/if}
                            </td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>下载附件</td>
                            {foreach $data as $v}
                            <td>
                                <label class="mui-switch-box">
                                    
                                    <input data-type="down" data-gid="{$v.gid}" class='tgl tgl-ios' id='cb6{$v.gid}' type='checkbox' {if $v['json']['down']}checked{/if}>
                                    <label class='tgl-btn' for='cb6{$v.gid}'></label>
                                </label>
                                
                            </td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>上传附件</td>
                            {foreach $data as $v}
                            <td>
                                {if $v['gid'] != 3}
                                <label class="mui-switch-box">
                                    
                                    <input data-type="uploadfile" data-gid="{$v.gid}" class='tgl tgl-ios' id='cb7{$v.gid}' type='checkbox' {if $v['json']['uploadfile']}checked{/if}>
                                    <label class='tgl-btn' for='cb7{$v.gid}'></label>
                                </label>
                                {/if}
                            </td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>上传视频</td>
                            {foreach $data as $v}
                            <td>
                                {if $v['gid'] != 3}
                                <label class="mui-switch-box">
                                    
                                    <input data-type="uploadvideo" data-gid="{$v.gid}" class='tgl tgl-ios' id='uploadvideo-{$v.gid}' type='checkbox' {if $v['json']['uploadvideo']}checked{/if}>
                                    <label class='tgl-btn' for='uploadvideo-{$v.gid}'></label>
                                </label>
                                {/if}
                            </td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>上传音频</td>
                            {foreach $data as $v}
                            <td>
                                {if $v['gid'] != 3}
                                <label class="mui-switch-box">
                                    
                                    <input data-type="uploadaudio" data-gid="{$v.gid}" class='tgl tgl-ios' id='uploadaudio-{$v.gid}' type='checkbox' {if $v['json']['uploadaudio']}checked{/if}>
                                    <label class='tgl-btn' for='uploadaudio-{$v.gid}'></label>
                                </label>
                                {/if}
                            </td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>隐藏帖子</td>
                            {foreach $data as $v}
                            <td>
                                {if $v['gid'] != 3}
                                <label class="mui-switch-box">
                                    
                                    <input data-type="thide" data-gid="{$v.gid}" class='tgl tgl-ios' id='cb8{$v.gid}' type='checkbox' {if $v['json']['thide']}checked{/if}>
                                    <label class='tgl-btn' for='cb8{$v.gid}'></label>
                                </label>
                                {/if}
                            </td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>帖子收费</td>
                            {foreach $data as $v}
                            <td>
                                {if $v['gid'] != 3}
                                <label class="mui-switch-box">
                                    
                                    <input data-type="tgold" data-gid="{$v.gid}" class='tgl tgl-ios' id='cb9{$v.gid}' type='checkbox' {if $v['json']['tgold']}checked{/if}>
                                    <label class='tgl-btn' for='cb9{$v.gid}'></label>
                                </label>
                                {/if}
                            </td>
                            {/foreach}
                        </tr>
                        <tr>
                            <td>免金币购买</td>
                            {foreach $data as $v}
                            <td>
                                <label class="mui-switch-box">
                                    
                                    <input data-type="nogold" data-gid="{$v.gid}" class='tgl tgl-ios' id='cb10{$v.gid}' type='checkbox' {if $v['json']['nogold']}checked{/if}>
                                    <label class='tgl-btn' for='cb10{$v.gid}'></label>
                                </label>
                            </td>
                            {/foreach}
                        </tr>

                    </tbody>
                </table>
                
            </div>
           
            

        </div><!-- ENd box  -->

    </div>

<!-- Modal -->
    <form method="post">
    <div class="modal fade" id="normalModal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">添加分类</h4>
                </div>
                <div class="modal-body">
                    <input type="hidden" name="gn" value="add">
                    <div class="form-group">
                        <label for="">用户组 ID</label>
                        <input type="text" name="id" class="form-control" value="<?php $i=-1; foreach ($usergroup as $v) {
                                if($v['gid'] > $i)
                                    $i = $v['gid'];
                            }echo $i+1; ?>">
                        <span>如果这个ID与上面的出现重复,请自行修改 , 请勿使用 0 </span>
                    </div>
                    <div class="form-group">
                        <label for="">用户组 名称</label>
                        <input type="text" name="name" class="form-control" >

                    </div>
                    <div class="row">
                        
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="">积分所处(最低)</label>
                                <input type="text" name="credits" class="form-control" value="-1">
                                <span></span>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="">积分所处(最高)</label>
                                <input type="text" name="credits_max" class="form-control" value="-1">
                                <span></span>
                            </div>
                        </div>
                        <div class="col-md-12">
                            
                            <div class="alert alert-info alert-custom alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                                <i class="fa fa-exclamation-circle m-right-xs"></i><strong>升级积分说明!</strong> 最低处写：0 最高处写：49 . 用户如果积分在 0 ~ 49 中 则使用该用户组。 如果最低 最高 任意一项填写 -1 都代表无法升级该用户组
                            </div>

                        </div>
                    </div>
                    
                    <div class="form-group">
                        <label for="">文件空间大小(kb) 注意单位</label>
                        <input type="text" name="space_size" class="form-control" value="51200">
                        <span>"1024" 代表只有 "1M的上传储存空间大小", "1024*(N) = M" 给予多大的空间 . 建议: "51200", 也就是50M </span>
                    </div>
                    <div class="form-group">
                        <label for="">聊天记录储存空间大小(b) 注意单位</label>
                        <input type="text" name="chat_size" class="form-control" value="4294967295">
                        <span>填入 "1024" 代表 1KB, "4294967295" (4G)为最大</span>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">提交</button>
                </div>
            </div>
        </div>
    </div>
    </form>

    <form method="post">
    <div class="modal fade" id="normalModal1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">修改用户组</h4>
                </div>
                <div class="modal-body">
                   <input type="hidden" name="gn" value="edit">
                    <input type="hidden" name="iid" id="edit-iid">

                    <div class="form-group">
                        <label for="">用户组 ID</label>
                        <input name="id" id="edit-id" type="text" class="form-control" >
                    </div>
                    <div class="form-group">
                        <label for="">用户组 名称</label>
                        <input name="name" id="edit-name" type="text" class="form-control" >
                    </div>
                    <div class="row">
                        
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="">积分所处(最低)</label>
                                <input type="text" id="edit-credits" name="credits" class="form-control" value="-1">
                                <span></span>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="">积分所处(最高)</label>
                                <input type="text" id="edit-credits-max" name="credits_max" class="form-control" value="-1">
                                <span></span>
                            </div>
                        </div>
                        <div class="col-md-12">
                            
                            <div class="alert alert-info alert-custom alert-dismissible" role="alert">
                                <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                                <i class="fa fa-exclamation-circle m-right-xs"></i><strong>升级积分说明!</strong> 最低处写：0 最高处写：49 . 用户如果积分在 0 ~ 49 中 则使用该用户组。 如果最低 最高 任意一项填写 -1 都代表无法升级该用户组
                            </div>

                        </div>
                    </div>
                    <span>输入 -1 代表该用户组是无法通过积分升级的!</span>
                    <div class="form-group">
                        <label for="">文件空间大小</label>
                        <input name="space_size" id="edit-space-size" type="text" class="form-control" >
                    </div>
                    <div class="form-group">
                        <label for="">聊天记录储存空间大小</label>
                        <input name="chat_size" id="edit-chat-size" type="text" class="form-control" >
                    </div>
                    <div class="form-group">
                        <label for="">字体颜色</label>
                        <input name="font_color" id="edit-font-color" type="text" class="form-control" >
                    </div>
                    <div class="form-group">
                        <label for="">额外CSS</label>
                        <textarea class="form-control" name="font_css" id="edit-font-css"></textarea>
                        <span>用户组名称外还包裹着一层font元素，可以在此元素下增加额外的CSS 用于包裹用户组名称</span>
                    </div>
                
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">提交</button>
                </div>
            </div>
        </div>
    </div>
    </form>
    <!-- !Modal -->
{include footer}
